<?php
// Change logs
//  Sep 9, 2011 - trungdt - Add aggregate
// 5/8/2010: Immanuel192 write this modeller

class sermonmodule_sermon {
	function form($object,$config) {
		global $db;
		
		if (!defined('SYS_FORMS')) require_once(BASE.'subsystems/forms.php');
		exponent_forms_initialize();

		$form = new form();
		if (!isset($object->id)) {
			$object->name="";
			$object->author = '';
			$object->download = 0;
			$object->date=time();
			$object->mp3_file=-1;$object->ppt_file=-1;
			$object->pdf_file=-1;$object->doc_file=-1;
            $object->series_name = '';
		} else {
			$form->meta('id',$object->id);
		}
		
		// get all current pastors in this module for combobox
		$pastors_temp=$db->selectDropdown("sermonmodule_sermon","author","1 GROUP BY author");
		$pastors=array();
		$pastors['no_selected']="---- Add new ----";
		foreach ($pastors_temp as $k=>$v)
		{
            if (trim($v)!="")
            {
                $pastors[$v]=$v;
            }
        }
		$form->register('name','Name',new textcontrol($object->name));
		
        $form->register('author_dropdown',"Pastor",new dropdowncontrol("no_selected",$pastors));
        $form->register(null,'',new htmlcontrol('<p>Please select name of the pastor of this sermon in the combobox or type the new one to add new pastor</p>'));
		$form->register('author','',new textcontrol($object->author));
        
        // Sept 23, 2010: trungdt - Add sermon series - begin
        $series_temp=$db->selectDropdown("sermonmodule_sermon","series_name","1 GROUP BY series_name");
        $series=array();
        $series['no_selected']="---- Add new ----";
        foreach ($series_temp as $k=>$v)
        {
            if (trim($v)!="")
            {
                $series[$v]=$v;      
            }
        }
        $form->register('series_dropdown',"Series",new dropdowncontrol("no_selected",$series));
        $form->register(null,'',new htmlcontrol('<p>Please select series of this sermon in the combobox or type the new one. If this sermon does not belong to any series, leave textbox blank.</p>'));
        $form->register('series_name','',new textcontrol($object->series_name));
        // Sept 23, 2010: trungdt - Add sermon series - end
		
		$form->register('date','Date',new datetimecontrol($object->date, true, false));
        
		$form->register('mp3_file','Mp3 File', new ajax_select_file("mp3_file",$config->mp3_col,$object->mp3_file,true));
		$form->register('doc_file','Document File (.doc .docx)', new ajax_select_file("doc_file",$config->doc_col,$object->doc_file,false));
		$form->register('pdf_file','PDF File (.pdf)', new ajax_select_file("pdf_file",$config->pdf_col,$object->pdf_file,false));
		$form->register('ppt_file','Powerpoint Slide (.ppt; .pttx)', new ajax_select_file("ppt_file",$config->ppt_col,$object->ppt_file,false));		
		$form->register('submit','',new buttongroupcontrol('Save','','Cancel'));
		return $form;
	}

	function update($values,$object) {
		$object->name = $values['name'];
		// for pastor name
		$object->author=$values['author'];
		if (!($values['author_dropdown']=='no_selected'))
			$object->author=$values['author_dropdown'];
            
        // Sept 23, 2010: trungdt - Add sermon series - begin
        // for pastor name
        $object->series_name=$values['series_name'];
        if (!($values['series_dropdown']=='no_selected'))
            $object->series_name=$values['series_dropdown'];
        // Sept 23, 2010: trungdt - Add sermon series - begin
        
		$object->date=mktime(0,0,0,$values['date_month'],$values['date_day'],$values['date_year']);
		$object->mp3_file = $values['mp3_file'];
		$object->doc_file = $values['doc_file'];
		$object->pdf_file = $values['pdf_file'];
		$object->ppt_file = $values['ppt_file'];
		return $object;
	}
}

?>
